﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZCrawler
{
    public class ZPublisherMapper
    {
        public List<string> OriginalKeys { get; set; }
        public List<string> MappedKeys { get; set; }
        public ZPublisherMapper()
        {
            OriginalKeys = new List<string>();
            MappedKeys = new List<string>();
        }
        public string GetOriKeyFromMappedKey(string key)
        {
            try
            {
                int index = MappedKeys.IndexOf(key);
                return OriginalKeys[index];
            }
            catch (Exception) { return null; }
        }

        public string GetMappedKeyFromOriKey(string key)
        {
            try
            {
                int index = OriginalKeys.IndexOf(key);
                return MappedKeys[index];
            }
            catch (Exception) { return null; }
        }

        public void SetOriKeyForGivenMapped(string ori_key, string map_key)
        {
            int index = MappedKeys.IndexOf(map_key);
            OriginalKeys[index] = ori_key;
        }
        public void SetMappedKeyForGivenOriKey(string ori_key,string map_key)
        {
            int idx = OriginalKeys.IndexOf(ori_key);
            MappedKeys[idx] = map_key;
        }
        public void RemoveAt(int index)
        {
            OriginalKeys.RemoveAt(index);
            MappedKeys.RemoveAt(index);
        }
        public void Add(string ori_key,string map_key)
        {
            OriginalKeys.Add(ori_key);
            MappedKeys.Add(map_key);
        }

        public int Count
        {
            get
            {
                return OriginalKeys.Count;
            }
        }
    }
}
